package driver.ui.driver;

import java.util.ArrayList;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import driver.ui.R;
import driver.ui.driver.Adapter.ActionlistAdapter;
import driver.ui.driver.Beans.action;

public class Contactmeeting extends Activity{
	private TextView mname;
	private ListView meetingactions;
	private ActionlistAdapter arrayAdapter;
	private TextView meetingname;
	 @Override
	  public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.meetingstatus);
	        Bundle extras = getIntent().getExtras();
			String name = extras.getString("name");			
	        meetingname=(TextView)findViewById(R.id.namemeeting);
	        meetingname.setText(name);
	        meetingactions = (ListView) findViewById(R.id.meetingactionList);
	        ArrayList<action>   actionlist= new ArrayList<action>();
	        //Initialize our array adapter notice how it references the contactlistitems.xml layout
	        arrayAdapter = new ActionlistAdapter(Contactmeeting.this, R.layout.actionitems,actionlist);
	        //Add actions
			action ac1=new action();
		    ac1.setImgsrc(R.drawable.meeting);
		    ac1.setName("Set up meeting");
		    actionlist.add(ac1);
		    action ac2=new action();
		    ac2.setImgsrc(R.drawable.pickup);
		    ac2.setName("Set up pickup");
		    actionlist.add(ac2);
		    action ac3=new action();
		    ac3.setImgsrc(R.drawable.call);
		    ac3.setName("Call Back");
		    actionlist.add(ac3);
		    action ac4=new action();
		    ac4.setImgsrc(R.drawable.sms);
		    ac4.setName("Send text message");
		    actionlist.add(ac4);
		    action ac5=new action();
		    ac5.setImgsrc(R.drawable.voicemail);
		    ac5.setName("Leave voicemail");
		    actionlist.add(ac5);
		    action ac6=new action();
		    ac6.setImgsrc(R.drawable.share);
		    ac6.setName("Share Status");
		    actionlist.add(ac6);
		    action ac7=new action();
		    ac7.setImgsrc(R.drawable.clock);
		    ac7.setName("Set up call reminder");
		    actionlist.add(ac7);
	 

	        
	        //Set the above adapter as the adapter of choice for our list
	        meetingactions.setAdapter(arrayAdapter);
	        
	        //Dialogs
	        final AlertDialog.Builder callblockBuilder=new AlertDialog.Builder(this);
	        final AlertDialog.Builder statusBuilder=new AlertDialog.Builder(this);
	        final AlertDialog.Builder shareBuilder=new AlertDialog.Builder(this);
	        
	   
	        mname=(TextView)findViewById(R.id.namemeeting);
	        //ListView's Listener
	        meetingactions.setOnItemClickListener(new OnItemClickListener(){

				@Override
				public void onItemClick(AdapterView<?> arg0, View arg1,
						int position, long arg3) {
					// TODO Auto-generated method stub
					
						if(position==2)
						{
						 //Call Block
							callblockBuilder.setCancelable(true);
							callblockBuilder.setIcon(R.drawable.alert);
							callblockBuilder.setTitle("Call Block");
							callblockBuilder.setMessage("David is not accepting calls at the moment. Would you like to share your status with David so that he may contact you at a convenient time?");
						    callblockBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
						    	
						    public void onClick(DialogInterface dialog, int id) {
						    						       		
						    	CharSequence[] StatusTime = {"15 minutes", "30 minutes", "1 hour", "2 hour"};					       					
						    	statusBuilder.setCancelable(true);
		       					statusBuilder.setIcon(R.drawable.timer);
		       					
		       					statusBuilder.setTitle("Share Status "+"with "+mname.getText()+" For");
		       					statusBuilder.setSingleChoiceItems(StatusTime, 0, new DialogInterface.OnClickListener ()
		       					{
		       						@Override

		       					    public void onClick(DialogInterface dialog, int id) {
		       						}

		       					});
		       					statusBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
			       			               public void onClick(DialogInterface dialog, int id) {
			       			            	   Intent addIntent=new Intent();
			       			            	   addIntent.setAction("Sharestatusconfirm");
			       			            	   startActivity(addIntent);
			       			            	   
			       			               }
			       			           })
			       			           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			       			               public void onClick(DialogInterface dialog, int id) {
			       			                    dialog.cancel();
			       			               }
			       			           });
			       				
			       					statusBuilder.show();
			       					} 
					       				
					                    
					               
					           })
					           .setNegativeButton("No Thanks", new DialogInterface.OnClickListener() {
					               public void onClick(DialogInterface dialog, int id) {
					                    dialog.cancel();
					               }
					           });
						
							callblockBuilder.show();
							}
						else if(position==5)
						{
						 	
							final CharSequence[] StatusTime = {"15 minutes", "30 minutes", "1 hour", "2 hour"};
							
							shareBuilder.setCancelable(true);
							shareBuilder.setIcon(R.drawable.timer);
							shareBuilder.setTitle("Share Status with "+mname.getText()+" For");
							shareBuilder.setSingleChoiceItems(StatusTime, 0, new DialogInterface.OnClickListener ()
							{
								public void onClick(DialogInterface dialog, int id) {
								}

							});
						    shareBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
					               public void onClick(DialogInterface dialog, int id) {		                    
					               }
					           })
					           .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
					               public void onClick(DialogInterface dialog, int id) {
					                    dialog.cancel();
					               }
					           });
						
							shareBuilder.show();
							} 
						
						
						
						
						

				}
	        });
										

	 }
	 }
